﻿using System;
using System.Windows.Data;

namespace GroupChallenge.Converters
{
    public class QuestionTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || parameter == null)
                return false;

            return value.ToString() == parameter.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object ret = value;

            // The boolean value means the option radion button was checked.
            if (value is bool &&
                (bool)value == true)
            {
                ret = Enum.Parse(targetType, parameter as string, true);
            }

            return ret;
        }
    }
}
